package com.lmq.interfaces;// interfaces/InterfaceCollision.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

interface I1 { void f(); }
interface I2 { int f(int i); }
interface I3 { int f(); }
class C { public int f() { return 1; } }

class C2 implements I1, I2 {
  @Override
  public void f() {}
  @Override
  public int f(int i) { return 1; } // Overloaded
}

class C3 extends C implements I2 {
  @Override
  public int f(int i) { return 1; } // Overloaded
}

class C4 extends C implements I3 {
  // Identical, no problem:
  @Override public int f() { return 1; }
}

// Methods differ only by return type:
//class C5 extends C implements I1 {}
//interface I4 extends I1, I3 {}
/**
 * using the same method name in different interface when you
 * expect those interface to be combined generally causes confusion in the readability
 * of the code.Strive to avoid it.
 */

// Adapting to an interface.
/**
 * One of the most compelling reasons for interfaces is to
 * allow multiple implementations for the same interface.In
 * simple cases this is in the form of a method that accepts an interface,
 * leaving it up to you to implement that interface and pass your
 * object to the method.
 * Thus, a common use for interfaces is the aforementioned Strategy
 * design pattern.You write a method that
 * performs ceritain operations,and that methods takes an interface
 * you also specify.You're basically saying, "You can use my method with any object
 * you like, as long as your abject conforms to my interface.
 * This makes your method more flexible, general and reusable.
 * For example, the constructor for the Scanner class(which you'll
 * lean more about in the String chapter ) takes a Readable interface.You'll find that Readable is
 * not an argument for any other method in the Java standard library it was
 * created solely ofr Scanner,so Scanner doesn't constrain its argument to a particular class.This
 * way,Scanner can be make to work with more types.If you create a new class and you want it used with Scanner,
 * you make it Readable like this:
 *
 */
